<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>商城-购物车</title>

  <link rel="stylesheet" type="text/css" th:href="@{/static/lib/layui-v2.6.3/css/layui.css}"/>
  <script type="text/javascript" th:src="@{/static/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>
  <script type="text/javascript" th:src="@{/static/lib/layui-v2.6.3/layui.js}"></script>
</head>
<body>
<form id="form1" action="" method="" class="layui-form">
    <div class="layui-form-item" style="width: 300px;display:inline-block;">
        <label class="layui-form-label">充值金额:</label>
        <div class="layui-input-block">
            <input id="a" th:onblur="hh()" type="text" name="amount" placeholder="请输入金额" class="layui-input">
        </div>
    </div>
    <button type="button" th:onclick="gg()">确定充值</button>
    <button type="button" style="width: 100px;display:inline-block;" th:onclick="bb()">100</button>
    <button type="button" style="width: 100px;display:inline-block;" th:onclick="cc()">500</button>
    <button type="button" style="width: 100px;display:inline-block;" th:onclick="dd()">1000</button>
    <button type="button" style="width: 100px;display:inline-block;" th:onclick="ee()">5000</button>
    <button type="button" style="width: 100px;display:inline-block;" th:onclick="ff()">10000</button>
</form>
</body>
<script>
    function bb(){
    $("#a").val(100);
    }
     function cc(){
    $("#a").val(500);
    }
     function dd(){
    $("#a").val(1000);
    }
     function ee(){
    $("#a").val(5000);
    }
     function ff(){
    $("#a").val(10000);
    }
    //金额的正则表达式
    function hh(){
    var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/;
    if(!reg.test($("#a").val()) || $(obj).val()==''){
     $("#a").val(0);
    }
    }
    function gg(){
    var params = $("#form1").serialize();
    	$.ajax({
					url: "/user/recharge1",
					type: "post",
					data: params,
					//请求发送完之后的回调函数
					success: function(info) {
						if (info == 1) {
							alert("充值成功！");
						} else {
							alert("充值失败！");
						}
						var index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
						//刷新父类页面
						window.parent.location.reload();
					}
				});
    }


</script>
</html>